Subject: [PATCH] add deprecation annotation support
---
Index: plugin/kubernetes/kubernetes.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/plugin/kubernetes/kubernetes.go b/plugin/kubernetes/kubernetes.go
--- a/plugin/kubernetes/kubernetes.go	(revision ae2bbc29be1aaae0b3ded5d188968a6c97bb3144)
+++ b/plugin/kubernetes/kubernetes.go	(date 1698920824817)
@@ -472,6 +472,9 @@
 
 				for _, eps := range ep.Subsets {
 					for _, addr := range eps.Addresses {
+						if !addr.Ready && !svc.HasAlphaPublishUnreadyAddressesAnnotation {
+							continue
+						}
 						// See comments in parse.go parseRequest about the endpoint handling.
 						if r.endpoint != "" {
 							if !match(r.endpoint, endpointHostname(addr, k.endpointNameMode)) {
Index: plugin/kubernetes/object/endpoint.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/plugin/kubernetes/object/endpoint.go b/plugin/kubernetes/object/endpoint.go
--- a/plugin/kubernetes/object/endpoint.go	(revision ae2bbc29be1aaae0b3ded5d188968a6c97bb3144)
+++ b/plugin/kubernetes/object/endpoint.go	(date 1698920604996)
@@ -34,6 +34,7 @@
 	Hostname      string
 	NodeName      string
 	TargetRefName string
+	Ready         bool
 }
 
 // EndpointPort is a tuple that describes a single port.
@@ -84,11 +85,9 @@
 	}
 
 	for _, end := range ends.Endpoints {
-		if !endpointsliceReady(end.Conditions.Ready) {
-			continue
-		}
 		for _, a := range end.Addresses {
 			ea := EndpointAddress{IP: a}
+			ea.Ready = endpointsliceReady(end.Conditions.Ready)
 			if end.Hostname != nil {
 				ea.Hostname = *end.Hostname
 			}
@@ -151,7 +150,7 @@
 			Ports:     make([]EndpointPort, len(eps.Ports)),
 		}
 		for j, a := range eps.Addresses {
-			ea := EndpointAddress{IP: a.IP, Hostname: a.Hostname, NodeName: a.NodeName, TargetRefName: a.TargetRefName}
+			ea := EndpointAddress{IP: a.IP, Hostname: a.Hostname, NodeName: a.NodeName, TargetRefName: a.TargetRefName, Ready: a.Ready}
 			sub.Addresses[j] = ea
 		}
 		for k, p := range eps.Ports {
Index: plugin/kubernetes/kubernetes_test.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/plugin/kubernetes/kubernetes_test.go b/plugin/kubernetes/kubernetes_test.go
--- a/plugin/kubernetes/kubernetes_test.go	(revision ae2bbc29be1aaae0b3ded5d188968a6c97bb3144)
+++ b/plugin/kubernetes/kubernetes_test.go	(date 1698920980350)
@@ -126,7 +126,7 @@
 			Subsets: []object.EndpointSubset{
 				{
 					Addresses: []object.EndpointAddress{
-						{IP: "172.0.0.1", Hostname: "ep1a"},
+						{IP: "172.0.0.1", Hostname: "ep1a", Ready: true},
 					},
 					Ports: []object.EndpointPort{
 						{Port: 80, Protocol: "tcp", Name: "http"},
@@ -141,7 +141,7 @@
 			Subsets: []object.EndpointSubset{
 				{
 					Addresses: []object.EndpointAddress{
-						{IP: "172.0.0.2"},
+						{IP: "172.0.0.2", Ready: true},
 					},
 					Ports: []object.EndpointPort{
 						{Port: 80, Protocol: "tcp", Name: "http"},
@@ -156,7 +156,7 @@
 			Subsets: []object.EndpointSubset{
 				{
 					Addresses: []object.EndpointAddress{
-						{IP: "10.9.8.7", NodeName: "test.node.foo.bar"},
+						{IP: "10.9.8.7", NodeName: "test.node.foo.bar", Ready: true},
 					},
 				},
 			},
@@ -171,7 +171,7 @@
 			Subsets: []object.EndpointSubset{
 				{
 					Addresses: []object.EndpointAddress{
-						{IP: "172.0.0.1", Hostname: "ep1a"},
+						{IP: "172.0.0.1", Hostname: "ep1a", Ready: true},
 					},
 					Ports: []object.EndpointPort{
 						{Port: 80, Protocol: "tcp", Name: "http"},
@@ -186,7 +186,7 @@
 			Subsets: []object.EndpointSubset{
 				{
 					Addresses: []object.EndpointAddress{
-						{IP: "172.0.0.2"},
+						{IP: "172.0.0.2", Ready: true},
 					},
 					Ports: []object.EndpointPort{
 						{Port: 80, Protocol: "tcp", Name: "http"},
@@ -201,7 +201,7 @@
 			Subsets: []object.EndpointSubset{
 				{
 					Addresses: []object.EndpointAddress{
-						{IP: "172.0.0.2"},
+						{IP: "172.0.0.2", Ready: true},
 					},
 					Ports: []object.EndpointPort{
 						{Port: 80, Protocol: "tcp", Name: "http"},
@@ -216,7 +216,7 @@
 			Subsets: []object.EndpointSubset{
 				{
 					Addresses: []object.EndpointAddress{
-						{IP: "10.9.8.7", NodeName: "test.node.foo.bar"},
+						{IP: "10.9.8.7", NodeName: "test.node.foo.bar", Ready: true},
 					},
 				},
 			},
Index: plugin/kubernetes/object/service.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/plugin/kubernetes/object/service.go b/plugin/kubernetes/object/service.go
--- a/plugin/kubernetes/object/service.go	(revision ae2bbc29be1aaae0b3ded5d188968a6c97bb3144)
+++ b/plugin/kubernetes/object/service.go	(date 1698920604997)
@@ -2,6 +2,7 @@
 
 import (
 	"fmt"
+	"strconv"
 
 	api "k8s.io/api/core/v1"
 	meta "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -20,6 +21,8 @@
 	ExternalName string
 	Ports        []api.ServicePort
 
+	HasAlphaPublishUnreadyAddressesAnnotation bool
+
 	// ExternalIPs we may want to export.
 	ExternalIPs []string
 
@@ -46,6 +49,10 @@
 		ExternalIPs: make([]string, len(svc.Status.LoadBalancer.Ingress)+len(svc.Spec.ExternalIPs)),
 	}
 
+	if v, ok := obj.GetAnnotations()["service.alpha.kubernetes.io/tolerate-unready-endpoints"]; ok {
+		s.HasAlphaPublishUnreadyAddressesAnnotation, _ = strconv.ParseBool(v)
+	}
+
 	if len(svc.Spec.ClusterIPs) > 0 {
 		s.ClusterIPs = make([]string, len(svc.Spec.ClusterIPs))
 		copy(s.ClusterIPs, svc.Spec.ClusterIPs)
@@ -93,7 +100,8 @@
 		ExternalName: s.ExternalName,
 		ClusterIPs:   make([]string, len(s.ClusterIPs)),
 		Ports:        make([]api.ServicePort, len(s.Ports)),
-		ExternalIPs:  make([]string, len(s.ExternalIPs)),
+		HasAlphaPublishUnreadyAddressesAnnotation: s.HasAlphaPublishUnreadyAddressesAnnotation,
+		ExternalIPs: make([]string, len(s.ExternalIPs)),
 	}
 	copy(s1.ClusterIPs, s.ClusterIPs)
 	copy(s1.Ports, s.Ports)
Index: plugin/kubernetes/handler_test.go
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/plugin/kubernetes/handler_test.go b/plugin/kubernetes/handler_test.go
--- a/plugin/kubernetes/handler_test.go	(revision ae2bbc29be1aaae0b3ded5d188968a6c97bb3144)
+++ b/plugin/kubernetes/handler_test.go	(date 1698920825251)
@@ -706,7 +706,7 @@
 		Subsets: []object.EndpointSubset{
 			{
 				Addresses: []object.EndpointAddress{
-					{IP: "172.0.0.100"},
+					{IP: "172.0.0.100", Ready: true},
 				},
 				Ports: []object.EndpointPort{
 					{Port: 53, Protocol: "udp", Name: "dns"},
@@ -721,7 +721,7 @@
 		Subsets: []object.EndpointSubset{
 			{
 				Addresses: []object.EndpointAddress{
-					{IP: "172.0.0.1", Hostname: "ep1a"},
+					{IP: "172.0.0.1", Hostname: "ep1a", Ready: true},
 				},
 				Ports: []object.EndpointPort{
 					{Port: 80, Protocol: "tcp", Name: "http"},
@@ -749,12 +749,12 @@
 		Subsets: []object.EndpointSubset{
 			{
 				Addresses: []object.EndpointAddress{
-					{IP: "172.0.0.2"},
-					{IP: "172.0.0.3"},
-					{IP: "172.0.0.4", Hostname: "dup-name"},
-					{IP: "172.0.0.5", Hostname: "dup-name"},
-					{IP: "5678:abcd::1"},
-					{IP: "5678:abcd::2"},
+					{IP: "172.0.0.2", Ready: true},
+					{IP: "172.0.0.3", Ready: true},
+					{IP: "172.0.0.4", Hostname: "dup-name", Ready: true},
+					{IP: "172.0.0.5", Hostname: "dup-name", Ready: true},
+					{IP: "5678:abcd::1", Ready: true},
+					{IP: "5678:abcd::2", Ready: true},
 				},
 				Ports: []object.EndpointPort{
 					{Port: 80, Protocol: "tcp", Name: "http"},
@@ -769,7 +769,7 @@
 		Subsets: []object.EndpointSubset{
 			{
 				Addresses: []object.EndpointAddress{
-					{IP: "172.0.0.20"},
+					{IP: "172.0.0.20", Ready: true},
 				},
 				Ports: []object.EndpointPort{{Port: -1}},
 			},
